StudentsPerformance <- read.csv("C:/Users/ASUS/Downloads/New_data.csv")
library(ggplot2)
library(plotly)
library(shiny)
Trong phần này, dữ liệu được trực quan hóa thông qua các biểu đồ
Histogram và Boxplot nhằm mô tả đặc điểm phân bố điểm số của học sinh,
cũng như đánh giá sự khác biệt giữa các nhóm nhân khẩu học và điều kiện
học tập. Việc trình bày dữ liệu bằng đồ thị giúp quan sát xu hướng tổng
quát, phát hiện các giá trị ngoại lai và hiểu rõ mức độ biến thiên của
từng biến trong bộ dữ liệu.
1. Trực quan hóa bằng đồ thị Histogram.
Khởi tạo đồ thị histogram sử dụng thư viện ggplot2
ggplot(StudentsPerformance, aes(x = total.score)) +
geom_histogram(fill = "steelblue", color = "black",alpha = 0.7) +
labs(title = "Phân phối total.score",
x = "total.score",
y = "Số lượng") +
theme_minimal()+
theme(plot.title = element_text(hjust = 0.5))
Đồ thị Histogram trên mô tả phân bố total.score của 1000 học
sinh trong tập dữ liệu. Quan sát đồ thị cho thấy:
2.Trực quan hóa bằng đồ thị Boxplot.
Khởi tạo lần lượt 5 đồ thị Boxplot sử dụng thư viện ggplot2
graph1 <- ggplot(
StudentsPerformance, aes(x=gender, y=total.score , fill=gender))+
geom_boxplot()+
labs(title= "Ảnh hưởng của gender lên total.score",x="gender",y="total.score")+
scale_fill_brewer(palette = "Set2")+ #đổi màu biểu đồ
theme(legend.position="none", plot.title = element_text(hjust = 0.5, size = 13)
)
graph2 <- ggplot(
StudentsPerformance, aes(x=race.ethnicity, y=total.score, fill=race.ethnicity))+
geom_boxplot()+
labs(title="Ảnh hưởng của race.ethnicity lên total.score",x="race.ethnicity",y="total.score")+
scale_fill_brewer(palette="Pastel1")+
theme(legend.position="none", plot.title = element_text(hjust = 0.5, size = 13)
)
graph3 <- ggplot(
StudentsPerformance, aes(x=parental.level.of.education, y=total.score, fill=parental.level.of.education)) +
geom_boxplot()+
labs(title= "Ảnh hưởng của parental.level.of.education lên total.score",x="parental.level.of.education ",y="total.score") + scale_fill_brewer(palette = "PiYG")+
theme(legend.position="none", plot.title = element_text(hjust = 0.5, size = 13)
)
graph4 <- ggplot(
StudentsPerformance, aes(x=lunch, y=total.score, fill=lunch)) +
geom_boxplot()+
labs(title= "Ảnh hưởng của lunch lên total.score",
x="lunch",y="total.score") + scale_fill_brewer(palette = "Paired")+
theme(legend.position="none", plot.title = element_text(hjust = 0.5, size = 13)
)
graph5 <- ggplot(
StudentsPerformance, aes(x=test.preparation.course, y=total.score, fill=test.preparation.course)) +
geom_boxplot()+
labs(title= "Ảnh hưởng của test.preparation.course\n lên total.score",
x="test.preparation.course",y="total.score") + scale_fill_brewer(palette = "Set3")+
theme(legend.position="none", plot.title = element_text(hjust = 0.5, size = 13)
)
Nhận xét:
Đồ thị Boxplot phân phối total.score theo
gender:
Đồ thị Boxplot phân phối total.score theo
race.ethnicity:
Đồ thị Boxplot phân phối total.score theo
parental.level.of.education:
Đồ thị Boxplot phân phối total.score theo
lunch:
Đồ thị Boxplot phân phối total.score theo
test.preparation.course:
Tóm lại, các biến gender, race.ethnicity, parental.level.of.education, lunch và test.preparation.course đều có ảnh hưởng đáng kể đến total.score, và cần được xem xét kỹ khi phân tích và xây dựng mô hình dự đoán kết quả học tập.